<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('患者列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list" style="display: none">
                    <ul>
                        <li>
                            <label>用户编号：</label>
                            <input type="text" name="userId"/>
                        </li>
                        <li>
                            <label>患者姓名：</label>
                            <input type="text" name="patientName"/>
                        </li>
                        <li>
                            <label>出生日期：</label>
                            <input type="text" class="time-input" placeholder="请选择出生日期" name="birthday"/>
                        </li>
                        <li>
                            <label>患者性别：</label>
                            <select name="patientSex" th:with="type=${@dict.getType('sys_user_sex')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>患者地址：</label>
                            <input type="text" name="address"/>
                        </li>
                        <li>
                            <label>患者手机号码：</label>
                            <input type="text" name="phone"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:patient:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:patient:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:patient:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:patient:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:patient:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:patient:remove')}]];
    var patientSexDatas = [[${@dict.getType('sys_user_sex')}]];
    var prefix = ctx + "system/patient";

    //开通登录帐号


    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "患者",
            columns: [{
                checkbox: true
            },
                {
                    field: 'patientId',
                    title: '患者编号',
                    visible: false
                },
                // {
                //     field: 'userId',
                //     title: '用户编号'
                // },
                {
                    field: 'patientName',
                    title: '患者姓名'
                },
                {
                    field: 'birthday',
                    title: '出生日期'
                },
                {
                    field: 'patientSex',
                    title: '患者性别',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(patientSexDatas, value);
                    }
                },
                {
                    field: 'address',
                    title: '患者地址'
                },
                {
                    field: 'phone',
                    title: '患者手机号码'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.patientId + '\')"><i class="fa fa-edit"></i>完善个人资料</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.patientId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        if(row.userId===undefined||row.userId===null||row.userId.length===0){
                            actions.push('<a style=" margin-left: 5px" class="btn btn-info btn-xs ' +  removeFlag+'" href="javascript:void(0)" onclick="fun(\'' + row.patientId + '\')"><i class="fa fa-user-plus"></i>开通登录帐号</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);


    });

    let fun= function(uuid){
        // $.operate.post("/registerDoctor/"+uuid);
        $.modal.confirm("是否确定为该患者用户开通登录帐号，密码默认为123456",function(){
            $.ajax({
                url:"/registerPatient/"+uuid,
                method:"post",
                success:function(res){
                    //console.log(res);
                    if(res.code===0){
                        $.modal.msgSuccess("开通成功");
                        $.table.refresh();
                    }else if(res.code===500){
                        $.modal.msgError(res.msg);
                    }

                },
                error:function(err){
                    //console.error(err);
                    $.modal.msgError(err);

                }

            })
        });

    }
</script>
</body>
</html>